/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package parserosm;


import aima.core.agent.Action;
import aima.core.search.framework.StepCostFunction;
import aimax.osm.reader.*;
import aimax.osm.data.OsmMap;
import aimax.osm.data.entities.MapNode;
import aimax.osm.data.impl.DefaultMap;
import aimax.osm.data.impl.DefaultMapBuilder;
import aimax.osm.data.MapWayAttFilter;
import aimax.osm.data.MapWayFilter;
import java.io.File;

//---------------PRUEBA


import aimax.osm.routing.*;
import java.util.*;



/**
 *
 * @author Corlo
 */
public class ParserOsm {

    protected OsmReader mapReader = new OsmReader();;
    protected DefaultMap hand= new DefaultMap();;
    protected MapWayFilter wayFilter;


    public ParserOsm(File file){
        DefaultMapBuilder builder= new DefaultMapBuilder(this.hand);
        this.mapReader.readMap(file, builder);
        this.hand=(DefaultMap) builder.buildMap();
        this.wayFilter = createMapWayFilter(hand, 0);
    }

    public void crearMapa(){
        MapNode node;
        ArrayList<MapNode> locs = new ArrayList();
        node = this.hand.getNode(312457827);
        OsmActionsFunction act = new OsmActionsFunction(wayFilter, true, node);
        Set<Action> actions = act.actions(node);
        StepCostFunction stepcost=new OsmDistanceStepCostFunction();
        for(Action ac:actions){
            List<MapNode> nodes = ((OsmMoveAction) ac).getNodes();
            MapNode to = ((OsmMoveAction) ac).getTo();
            double c = stepcost.c(node, ac, act);
//            System.out.print(ac);
//            System.out.print(to);
//            System.out.print(nodes);
//            System.out.println(c);
        }

    }

    public DefaultMap gethand(){
        return this.hand;
    }

    public MapNode getnode(long id){
        return this.hand.getNode(id);
    }

    private MapWayFilter createMapWayFilter(OsmMap map, int waySelection) {
		if (waySelection == 1)
			return MapWayAttFilter.createCarWayFilter();
		else if (waySelection == 2)
			return MapWayAttFilter.createBicycleWayFilter();
		else
			return MapWayAttFilter.createAnyWayFilter();
	}

}
